package com.qumitech.visualnovel.component.asyctask;

import com.qumitech.visualnovel.component.util.TimeUtils;
import com.qumitech.visualnovel.service.script.ScriptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.qumitech.visualnovel.service.novel.ReviewService;

import java.util.Date;

@Slf4j
@Component
public class ScriptTask {
    @Autowired
    ReviewService reviewService;
    @Autowired
    ScriptService scriptService;



    @Scheduled(fixedRate = 180 * 1000)
    public void publishTask() {
        reviewService.publishTask();
    }


    // 每天1点30 运行脚本计算前一天数据统计
    @Scheduled(cron = "0 30 1 * * ?")
    public void processLogOneDay() {
        String lastDay = TimeUtils.formatDate(DateUtils.addDays(new Date(), -1));
        log.info("processLogOneDay,lastDay={}", lastDay);
        scriptService.processLogOneDay(lastDay);
    }
}
